package com.sanrenzu.chunbo.ui.fenlei.gengduo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;

import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.adapter.GengDuoGridView;
import com.sanrenzu.chunbo.bean.zxb.XinXianBean;
import com.sanrenzu.chunbo.bean.zxb.XinXianTitleBean;
import com.sanrenzu.chunbo.config.UrlConfig;
import com.sanrenzu.chunbo.widget.MyGirdView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by My on 2016/9/1.
 */
public class GengDuoFragment extends Fragment implements GengDuoContractF.View {


    public String tabIndex="";

    public static GengDuoFragment newInstance(String tabIndex) {

        GengDuoFragment fragment = new GengDuoFragment();
        Bundle bundle = new Bundle();
        bundle.putString("tabIndex", tabIndex);
        fragment.setArguments(bundle);
        return fragment;

    }

    @BindView(R.id.gengduo_gridview)
    MyGirdView gengduoGridview;

    private GengDuoContractF.Persenter persenter;
    private GengDuoGridView gengDuoGridViewAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_gengduo, container, false);
        persenter = new GengDuoPersenterF(this);
        Bundle bundle = getArguments();
        tabIndex = bundle.getString("tabIndex");
        Map<String,String> map  = new HashMap<>();
        //?city_id=35&num_page=1&class_id=1&xiaoqu_id=178973
        map.put(UrlConfig.Key.CITY_ID,"35");
        map.put(UrlConfig.Key.NUM_PAGE,tabIndex);
        map.put(UrlConfig.Key.XIAOQU_ID,"178973");

        persenter.getVerticalXinXian(map);

        ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onGetVerticalXinXianBean(XinXianBean xinXianBean) {
        List<XinXianTitleBean> xinXianTitleBean = xinXianBean.getTypeClassList();
        gengDuoGridViewAdapter = new GengDuoGridView(getActivity(), xinXianTitleBean);

        gengduoGridview.setAdapter(gengDuoGridViewAdapter);
    }
}
